﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Entity.Validators
{
    /// <summary>
    /// 实现统一验证基类
    /// （数据有效性验证）
    /// </summary>
    public abstract class EntityValidator
    {

        /// <summary>
        /// 数据验证(是否成功)
        /// 虚属性，子类可以根据自己的逻辑去复写
        /// </summary>
        public virtual bool IsValid { get { return (GetRuleViolations().Count() == 0); } }
        /// <summary>
        /// 获取验证失败的信息枚举
        /// 它使用了简单的迭代器,如果GetRuleViolations有错误则返回假
        /// </summary>
        /// <returns></returns>
        public abstract IEnumerable<RuleViolation> GetRuleViolations();
    }
}
